package com.kiki.stater.sort;

import java.util.Arrays;

/**
 * Created by mazeyi on 2021/3/11.
 */
public class QuikSortTest {

    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,9,8,7,6};
        quikSort(0,arr.length -1 ,arr);

        Arrays.stream(arr).boxed().forEach(x -> {
            System.out.println(x);
        });

    }

    public static  void quikSort(int low, int height, int[] arr){
        if(low >= height){
            return;
        }
        int i = low,j = height;
        int temp = arr[low];


        while (i < j){

            while (i < j && arr[j] > temp){
                //大于基准值继续
                j--;
            }
            if(i < j){
                arr[i] = arr[j];
                i ++;
            }

            while (i <j && arr[i] < temp){
               i++;
            }
            if(i < j){
                arr[j] = arr[i];
                j--;
            }

        }
        //i == j
        arr[i] = temp;
        quikSort(low,i - 1,arr);
        quikSort(i + 1,height, arr);

    }
}